#include <iostream>
#include <memory>
// #include <glog/logging.h>
using namespace std;

class Data 
{
public:
    Data(){cout << "Create data"<< endl;}
    ~Data(){cout << "Drop data" << endl;}
};

int main(int argc, char const *argv[])
{
    std::cout << "this is the code using unique pointer" << endl;
    // 1. unique_ptr 初始化
    // RAII 资源获取即初始化
    {
        unique_ptr<int> p1(new int);
        int* p6 = new int;
        unique_ptr<Data> p2(new Data);
        auto p3 = make_unique<Data>();

        cout << "=======1======" << endl;

        // 空智能指针
        // unique_ptr<Data> p4;
        unique_ptr<int []> pa1 = make_unique<int []> (1024);
        unique_ptr<int []> pa2(new int [1024]);
        unique_ptr<Data[]> pa3(new Data[5]);

        unique_ptr<Data> p7(new Data);
        unique_ptr<Data> p8 = std::move(p7);
        unique_ptr<Data> p9(new Data);
        
        // 支持移动赋值
        p7 = std::move(p9);

        // 重置空间
        p7.reset(new Data);

        // 主动释放空间
        p7 = nullptr;

        // 释放所有权
        auto ptr9 = p9.release();
        delete ptr9;

    }
    cout << "=======2======" << endl;
    cout << "test1" << endl;
    cout << "Just add a line here" << endl;
    cout << "3.2 21:07" << endl;
    return 0;
}
